import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class RedisDemoSet {
    public static void test1(Jedis jedis){
        System.out.println("sadd 和 smembers:");
        jedis.flushAll();
        jedis.sadd("key","1","2","3","4","5","6","7","8","9");
        Set<String> set = jedis.smembers("key");
        set.forEach(System.out::print);
    }
    public static void test2(Jedis jedis){
        System.out.println("sismember:");
        jedis.flushAll();
        jedis.sadd("key","1","2","3","4","5","6","7","8","9");
        System.out.println(jedis.sismember("key", "111"));
    }
    public static void test3(Jedis jedis){
        System.out.println("scard:");
        jedis.flushAll();
        jedis.sadd("key","1","2","3","4","5","6","7","8","9");
        long count = jedis.scard("key");
        System.out.println(count);
    }
    public static void test4(Jedis jedis){
        System.out.println("spop:");
        jedis.flushAll();
        jedis.sadd("key","1","2","3");
        String result = jedis.spop("key");
        System.out.println(result);
    }
    public static void test5(Jedis jedis){
        System.out.println("sinter :");
        jedis.flushAll();
        jedis.sadd("key","1","2","3");
        jedis.sadd("key2","1","2","4");
        Set<String> result= jedis.sinter("key","key2");
        System.out.println(result);
    }
    public static void test6(Jedis jedis){
        System.out.println("sinterstore:");
        jedis.flushAll();
        jedis.sadd("key","1","2","3","4");
        jedis.sadd("key2","1","2","4","5");
        jedis.sinterstore("key3","key","key2");
        Set<String> result = jedis.smembers("key3");
        System.out.println(result);
    }
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("127.0.0.1", 8888);
        try (Jedis jedis = jedisPool.getResource()) {
            test6(jedis);
        }
    }
}
